package cool.houge.pig.repository;

import cool.houge.pig.model.Sequence;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Mono;

/**
 * 序列.
 *
 * @author KK (kzou227@qq.com)
 */
public interface SequenceRepository extends ReactiveCrudRepository<Sequence, String> {

  /**
   * @param name
   * @return
   */
  @Query(
      "UPDATE t_sequence SET current_value=current_value+increment_value,update_time=CURRENT_TIMESTAMP WHERE name=:name")
  @Modifying
  Mono<Boolean> increment(String name);
}
